package com.breezelin.freshmarket.utils;

import com.breezelin.freshmarket.entities.data.UserInfo;

/**
 * Created by Breeze Lin
 * 2016/9/24 9:26
 * 1linyufeng1@gmail.com
 */

public final class UserUtil {
	private UserUtil() {
		// 封闭构造
	}

	/**
	 * 保存用户信息
	 *
	 * @param info 用户信息
	 */
	public static void saveUserData(UserInfo info) {
		LocalDataUtil.getInstance().put(
				LocalDataUtil.KEY_USERNAME,
				info.getUserName()
		);
		LocalDataUtil.getInstance().put(
				LocalDataUtil.KEY_SVR_TOKEN,
				info.getToken()
		);
		LocalDataUtil.getInstance().put(
				LocalDataUtil.KEY_USER_ID,
				info.getUserId()
		);
	}

	/**
	 * 保存密码
	 *
	 * @param password 密码
	 */
	public static void savePassword(String password) {
		LocalDataUtil.getInstance().put(
				LocalDataUtil.KEY_PASSWORD,
				password
		);
	}

	/**
	 * 清除用户数据
	 */
	public static void clearUserData() {
		LocalDataUtil.getInstance().put(LocalDataUtil.KEY_USERNAME, "");
		LocalDataUtil.getInstance().put(LocalDataUtil.KEY_PASSWORD, "");
		LocalDataUtil.getInstance().put(LocalDataUtil.KEY_SVR_TOKEN, "");
		LocalDataUtil.getInstance().put(LocalDataUtil.KEY_USER_ID, "");
	}
}
